package net.zjitc.dao.impl;

import net.zjitc.dao.AdminDao;
import net.zjitc.pojo.AdminUser;
import net.zjitc.utils.db.C3P0Utils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * Created by rj1502 on 2017/11/14.
 */
public class AdminDaoImpl implements AdminDao{
    public AdminUser findByUsernameAndPassword(String username, String password) {
        QueryRunner runner = new QueryRunner(C3P0Utils.getDataSource());
        String sql  = "select * from adminuser where username = ? and password =?";
        try {
            AdminUser admin = (AdminUser) runner.query(sql,new BeanHandler(AdminUser.class),username,password);
            return admin;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
